package com.itheima.blog.web.controller;



import com.itheima.blog.web.domain.po.TComment;
import com.itheima.blog.web.domain.vo.CommentVO;

import com.itheima.blog.web.service.ITCommentService;
import com.itheima.common.domain.PageReqDto;
import com.itheima.common.domain.PageResDto;
import com.itheima.common.domain.vo.BlogVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.blog.web.service.ITCommentService;
import com.itheima.common.domain.PageResDto;
import com.itheima.common.domain.R;
import com.itheima.common.domain.dto.CommentPageDto;
import com.itheima.common.domain.po.ResComment;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import com.itheima.blog.web.service.ITCommentService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 评论表 前端控制器
 * </p>
 *
 * @author hyf
 * @since 2023-07-12
 */
@RestController
@RequestMapping("/web/owner")
@RequiredArgsConstructor
public class TCommentController {
    private final ITCommentService commentService;
    /*
    * 查询一级评论
    * */
    @GetMapping("/comment/{blogId}")
    public R getBlogComment(@PathVariable("blogId") Long blogId){
        return commentService.getBlogComment(blogId);
    }
    /*
    * 查询二级评论
    * */
    @GetMapping("/comment/{blogId}/{commentId}")
    public R getReplyComment(@PathVariable("blogId")Long blogId,@PathVariable("commentId") Long commentId){
        return commentService.getRejectComment(blogId,commentId);
    }

    @PostMapping ("/comment/page")
    public PageResDto<ResComment> getCommentList(@RequestBody CommentPageDto commentPageDto){
        return commentService.getCommentList(commentPageDto);
    }

    @GetMapping("/comment/delete")
    public void deleteCommentByIds(@RequestParam("ids")List<Integer> ids){
        commentService.deleteCommentByIds(ids);
    }
    @ApiOperation("获取评论总数")
    @GetMapping("/comments")
    public Long getComments(){
        return commentService.getComments();
    }


@PostMapping("/comment/list")
@ApiOperation("展示我的评论")
public PageResDto<CommentVO> myCommentPage(@RequestBody PageReqDto pageReqDto){
    return commentService.myCommentPage(pageReqDto);
}
@PostMapping("/comment/reply")
@ApiOperation("展示回复我的评论")
public PageResDto<CommentVO> otherCommentPage(@RequestBody PageReqDto pageReqDto) {
    return commentService.otherCommentPage(pageReqDto);
}
    @DeleteMapping("/comment/list/{id}")
    @ApiOperation("删除我的评论")
    public void  rmMyComment(@PathVariable("id") Long id){
    commentService.rmMyComment(id);
}
    @DeleteMapping("/comment/reply/{id}")
    @ApiOperation("删除回复我评论的评论")
    public void  rmOtherComment(@PathVariable("id") Long id){
    commentService.removeById(id);
    }

}
